import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:znmm/UI/A_Common/custom_textField.dart';
import 'package:znmm/UI/utils/my_global.dart';
import 'package:znmm/config/app_color.dart';

import '../manage/cn_user_mag.dart';
import '../model/cn_user_model.dart';

class CnBasicInfoView extends StatefulWidget {
  const CnBasicInfoView({super.key});

  @override
  State<CnBasicInfoView> createState() => _CnBasicInfoViewState();
}

class _CnBasicInfoViewState extends State<CnBasicInfoView> {
  final CnUserModel _pModel = CnUserMag().getCnUserModel();

  String _firstName = "";
  String _lastName = '';
  String _email = "";

  @override
  void initState() {
    super.initState();

    _firstName = _pModel.firstName;
    _lastName = _pModel.lastName;
    _email = _pModel.email;
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    List<Widget> itemList = [];

    itemList.add(Padding(
      padding: const EdgeInsets.fromLTRB(20, 15, 20, 0),
      child: CustomTextField(
        onInputComplete: (value) {
          print(value);
          _firstName = value;
        },
        labelText: "First Name",
        strText: _firstName,
      ),
    ));

    itemList.add(Padding(
      padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
      child: CustomTextField(
        onInputComplete: (value) {
          print(value);
          _lastName = value;
        },
        labelText: "Last Name",
        strText: _lastName,
      ),
    ));

    itemList.add(Padding(
      padding: const EdgeInsets.fromLTRB(20, 10, 20, 0),
      child: CustomTextField(
        onInputComplete: (value) {
          print(value);
          _email = value;
        },
        labelText: "Email Address",
        strText: _email,
      ),
    ));

    return Scaffold(
        backgroundColor: AppColor.backgroundColor,
        appBar: MyGlobal.getNavigationBar(context, "Basic Info", actions: [
          TextButton(
            onPressed: () {
              CnUserMag().editUserinfo(
                firstName: _firstName,
                lastName: _lastName,
                email: _email,
                callback: () {
                  Get.back(result: true);
                },
              );
            },
            child: const Text(
              "Save",
              style: TextStyle(
                fontSize: 17,
                color: Colors.black,
              ),
            ),
          )
        ]),
        body: Container(
            margin: const EdgeInsets.only(bottom: 30), // 设置外边距
            child: Scrollbar(
              child: SingleChildScrollView(
                child: Column(
                  children: itemList,
                ),
              ),
            )));
  }
}
